/**
 * Created by PengWei on 2018/7/30.
 */


namespace game {
    import GObject = fairygui.GObject;
    import BaseView = mengdao.BaseView;

    export class ResizeUtils {

        /** 居中对齐显示 */
        public static POP_ALIGN_CENTER: string = "POP_ALIGN_CENTER";

        /** 宽度100%模式 */
        public static POP_FULL_WIDTH: string = "POP_FULL_WIDTH";


        public static resizePop(view: BaseView<any>, align: string): void {
            let s = Config.VIEW_SCALE;
            view.scale = s;

            if (align == this.POP_ALIGN_CENTER) {
                let viewWidth = view.getWidth();
                let viewHeight = view.getHeight();

                let sW = viewWidth * s;
                let sH = viewHeight * s;

                if (sW > Config.STAGE_WIDTH || sH > Config.STAGE_HEIGHT) {
                    sW = Config.STAGE_WIDTH / viewWidth;
                    sH = Config.STAGE_HEIGHT / viewHeight;
                    s = Math.min(sW, sH);
                    view.scale = s;
                }

                view.x = Config.STAGE_WIDTH * 0.5 - viewWidth * s * 0.5;
                view.y = Config.STAGE_HEIGHT * 0.5 - viewHeight * s * 0.5;
            }else{
                view.width = Math.round(Config.STAGE_WIDTH / s);
            }
        }
    }
}